package com.sh.data.engine.web.webapi.controller.api;


import com.sh.data.engine.domain.api.service.DataApiRestService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/restData")
@Tag(name = "数据服务-API管理-我的API", description = "数据服务-API管理-我的API")
@Slf4j
public class DataApiRestController {

    @Autowired
    private DataApiRestService dataApiRestService;

    @RequestMapping(
        value = "/**",
        method = {RequestMethod.GET, RequestMethod.POST})
    public Object service(HttpServletRequest request) throws Exception {
        String servletPath = request.getServletPath();

        String apiPath = servletPath.substring(DataApiRestService.SERVLETPATH.length());

        Object result = dataApiRestService.getResult(apiPath, request);

        return result;
    }
}
